package club.ljwang.jobs;

import club.ljwang.constant.RedisConstant;
import club.ljwang.utils.QiniuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @Auther: wangl
 * @Date: 2020/2/29 16:16
 * @Description:
 */

@Component
public class CleanImages {

    @Autowired
    private JedisPool jedisPool;

    public void run(){

        Jedis jedis = jedisPool.getResource();

        //注意 数据多的set集合放前面!!!
        Set<String> images = jedis.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);

        for (String image : images) {

            QiniuUtil.delete(image);
            System.out.println("已清理:"+image);
            jedis.srem(RedisConstant.SETMEAL_PIC_RESOURCES,image);
        }


        jedis.close();
    }
}
